<?php

namespace app\admin\controller;

use app\common\controller\Admin;
use think\Request;
use app\common\model\Block as blockModel;

class Block extends Admin {

    public $blockModel;

    public function __construct(Request $request = null) {
        parent::__construct($request);
        $this->blockModel = new blockModel();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index() {
        $list = $this->blockModel->select();
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function editblock() {
        $data = $this->request->param();
        if ($data['id']) {
            $this->blockModel->where('id', $data['id'])->update($data);
        } else {
            $this->blockModel->insert($data);
        }
        $this->success('操作成功');
    }

    /**
     * 更新排序
     */
    public function setOrder() {
        $param = $this->request->param();

        $this->_setorder($param['list_order'], 'block');

        $this->success('排序成功');
    }

    public function delblock($id) {
        $this->blockModel->where('id', $id)->delete();
        $this->success('删除成功');
    }

}
